﻿<!DOCTYPE html>
<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.bean.*,java.net.URLEncoder,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  User user = (User) session.getAttribute("user");
  if (user == null) {
    response.sendRedirect(request.getContextPath() + "/m/login");
    return;
  }
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> customerCategorys = companyInfo.customerCategorys;
  List<Map<String, Object>> taskCategory = companyInfo.taskCategorys;
  List<Map<String, Object>> companyTags = companyInfo.tags;
  List<User> users = companyInfo.users;
  List<Group> allGroups = companyInfo.getAllGroups();
  List<Group> publicGroups = companyInfo.getPublicGroups(user);
%>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>企客宝</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/iconfont.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/sm.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/sm-extend.min.css?ver=<%=Const.VERSION%>">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/mobileV2/css/mobile.css?ver=<%=Const.VERSION%>">

    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/zepto.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/sm.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/sm-extend.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/echarts.common.min.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/mobileV2/script/mobile.js?ver=<%=Const.VERSION%>' charset='utf-8'></script>
    <jsp:include page="mobileCommonJS.jsp" flush="true"/>
  </head>
  <body>
    <div class="page-group">
      <div class="page" id="page-activity">
        <header class="bar bar-nav">
          <h1 class="title">最新动态</h1>
          <a class="button button-link button-nav pull-right" id="link-note-refresh" href="#">
            <span class="icon iconfont icon-refresh"></span>
          </a>
        </header>
        <nav class="bar bar-tab">
          <a class="tab-item active" href="#">
            <span class="icon iconfont icon-activity"></span>
            <span class="tab-label">动态</span>
          </a>
          <a class="tab-item" href="#page-customer">
            <span class="icon iconfont icon-customer"></span>
            <span class="tab-label">客户</span>
          </a>
          <a class="tab-item" href="#page-deal">
            <span class="icon iconfont icon-deal"></span>
            <span class="tab-label">销售机会</span>
          </a>
          <a class="tab-item" href="#page-task">
            <span class="icon iconfont icon-task"></span>
            <span class="tab-label">任务</span>
          </a>
          <% if (user.isAdmin || user.isGroupAdmin) {%>
          <a class="tab-item" href="#page-statistics">
            <span class="icon iconfont icon-statistics"></span>
            <span class="tab-label">统计</span>
          </a>
          <%}%>
        </nav>
        <div class="content">
          <div id="note-list"></div>
          <div class="content-block">
            <p class="buttons-row">
              <a href="#" id="link-note-more" class="button button-success button-big" style="display:none;">查看更多...</a>
            </p>
          </div>
        </div>
      </div>

      <div class="page" id="page-customer">
        <header class="bar bar-nav">
          <a class="button button-link button-nav pull-left open-panel" id="link-customer-panel" href="#page-customer">
            <span class="icon iconfont icon-search2"></span>
          </a>
          <h1 class="title" id="customer-title"><span>我的客户</span> <i class="icon iconfont icon-arrowdown"></i></h1>
          <a class="button button-link button-nav pull-right" id="link-customer-refresh" href="#">
            <span class="icon iconfont icon-refresh"></span>
          </a>
        </header>
        <div class="bar bar-header-secondary">
          <div class="searchbar">
            <a class="searchbar-cancel">取消</a>
            <div class="search-input">
              <label class="icon iconfont icon-search" for="search"></label>
              <input type="search" id='search' placeholder='输入关键字...'/>
            </div>
          </div>
        </div>
        <nav class="bar bar-tab">
          <a class="tab-item" href="#page-activity">
            <span class="icon iconfont icon-activity"></span>
            <span class="tab-label">动态</span>
          </a>
          <a class="tab-item active" href="#">
            <span class="icon iconfont icon-customer"></span>
            <span class="tab-label">客户</span>
          </a>
          <a class="tab-item" href="#page-deal">
            <span class="icon iconfont icon-deal"></span>
            <span class="tab-label">销售机会</span>
          </a>
          <a class="tab-item" href="#page-task">
            <span class="icon iconfont icon-task"></span>
            <span class="tab-label">任务</span>
          </a>
          <% if (user.isAdmin || user.isGroupAdmin) {%>
          <a class="tab-item" href="#page-statistics">
            <span class="icon iconfont icon-statistics"></span>
            <span class="tab-label">统计</span>
          </a>
          <%}%>
        </nav>
        <div class="content">
          <div id="customer-list"></div>
          <div class="content-block">
            <p class="buttons-row">
              <a href="#" id="link-customer-more" class="button button-success button-big" style="display:none;">查看更多...</a>
            </p>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-permission-everyone" >
        <div class="content-block">
          <p>请选择查看的公海部门 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="customer-permission-public-group">
              <li v="*" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >全部公海客户</div>
                  </div>
                </div>
              </li>
<% if (publicGroups != null) {
    for (Group group:publicGroups) {%>
              <li v="<%=(group.getId() == 0 ? "":group.getId()) %>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=group.getIndentName()%>的公海客户</div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-permission-group" >
        <div class="content-block">
          <p>请选择查看的部门 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="customer-permission-group">
<% if (allGroups != null) {
    for (Group group:allGroups) {%>
              <li v="<%=group.getId() %>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=group.getIndentName()%></div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-permission-person" >
        <div class="content-block">
          <p>请选择查看的员工 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="customer-permission-person">
<% if (user.isAdmin) {%>
              <li v="*" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >所有员工的客户</div>
                  </div>
                </div>
              </li>
<%}%>
              <li v="<%=user.userId%>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >我的客户</div>
                  </div>
                </div>
              </li>
<%
  String groupName = "";
  for (User u : users) {
    if (u.userId.equals(user.userId)) {
      continue;
    }
    if (!companyInfo.isGroupAdmin(user, u.groupId)) {
      continue;
    }
    String gn = companyInfo.getGroupName(u);
    if (!groupName.equals(gn) && gn != null) {
       groupName = gn; %>
              <li class="list-group-title"><%=Util.HTMLEncode(groupName)%></li>
<%
    }
%>
              <li v="<%=u.userId%>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode(u.name)%>的客户</div>
                  </div>
                </div>
              </li>
<%
  }
%>
            </ul>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-category" >
        <div class="content-block">
          <p>请选择客户分类 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="customer-category-list">
              <li v="" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >全部分类</div>
                  </div>
                </div>
              </li>
              <li v="0" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >无分类</div>
                  </div>
                </div>
              </li>
<% if (customerCategorys != null) {
    for (Map<String, Object> category:customerCategorys) {%>
              <li v="<%=category.get("CategoryId") %>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode((String)category.get("CategoryName"))%></div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-customer-tag">
        <div class="content-block">
          <p>请选择客户标签 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="customer-tag-list">
              <li v="" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >全部标签</div>
                  </div>
                </div>
              </li>
<% if (companyTags != null) {
    for (Map<String, Object> tag:companyTags) {%>
              <li v="<%=tag.get("TagId") %>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode((String)tag.get("TagName"))%></div>
                  </div>
                </div>
              </li>
<%
    }
  } %>
            </ul>
          </div>
        </div>
      </div>

      <div class="panel-overlay"></div>

      <div class="panel panel-left panel-reveal theme-dark" id='panel-left-customer'>
        <div class="content-block">
          <p>请选择需要查看的客户</p>
        </div>
        <div class="list-block">
          <ul id="panel-left-customer-type">
            <li class="item-content item-link" v="<%=Const.VISIBLE_EVERYONE%>">
              <div class="item-inner">
                <div class="item-title">公海客户</div>
              </div>
            </li>
            <li class="item-content item-link" v="<%=Const.VISIBLE_PERSON%>">
              <div class="item-inner">
                <div class="item-title">按员工查看客户</div>
              </div>
            </li>
            <li class="item-content item-link" v="<%=Const.VISIBLE_GROUP%>">
              <div class="item-inner">
                <div class="item-title">按部门查看</div>
              </div>
            </li>
            <li class="item-content item-link" v="<%=Const.VISIBLE_SHARE_OWNER%>">
              <div class="item-inner">
                <div class="item-title">我共享的客户</div>
              </div>
            </li>
            <li class="item-content item-link" v="<%=Const.VISIBLE_SHARE_OTHER%>">
              <div class="item-inner">
                <div class="item-title">共享给我的客户</div>
              </div>
            </li>
          </ul>
        </div>

        <div class="list-block">
          <ul>
            <li class="item-content item-link" id="panel-left-customer-category">
              <div class="item-inner">
                <div class="item-title">按分类查看</div>
              </div>
            </li>
            <li class="item-content item-link" id="panel-left-customer-tag">
              <div class="item-inner">
                <div class="item-title">按标签查看</div>
              </div>
            </li>
          </ul>
        </div>
      </div>


      <div class="page" id="page-task">
        <header class="bar bar-nav">
          <a class="button button-link button-nav pull-left" href="#" id="link-show-add-task">
            <span class="icon iconfont icon-plus"></span>
          </a>
          <h1 class="title">任务</h1>
          <a class="button button-link button-nav pull-right" id="link-task-refresh" href="#">
            <span class="icon iconfont icon-refresh"></span>
          </a>
        </header>
        <nav class="bar bar-tab">
          <a class="tab-item" href="#page-activity">
            <span class="icon iconfont icon-activity"></span>
            <span class="tab-label">动态</span>
          </a>
          <a class="tab-item" href="#page-customer">
            <span class="icon iconfont icon-customer"></span>
            <span class="tab-label">客户</span>
          </a>
          <a class="tab-item" href="#page-deal">
            <span class="icon iconfont icon-deal"></span>
            <span class="tab-label">销售机会</span>
          </a>
          <a class="tab-item active" href="#">
            <span class="icon iconfont icon-task"></span>
            <span class="tab-label">任务</span>
          </a>
          <% if (user.isAdmin || user.isGroupAdmin) {%>
          <a class="tab-item" href="#page-statistics">
            <span class="icon iconfont icon-statistics"></span>
            <span class="tab-label">统计</span>
          </a>
          <%}%>
        </nav>
        <div class="content">
          <div class="content-block">
            <div class="buttons-row">
              <a href="#tab1" class="tab-link active button">进行中</a>
              <a href="#tab2" class="tab-link button">已完成</a>
            </div>
          </div>
          <div class="tabs">
            <div id="tab1" class="tab active">
              <div class="content-block" id="tasks-doing-container">
                <div class="text-center" id="tasks-doing-none" style="display:none;">没有任务</div>
                <div id="overdueTasks" style="display:none;">
                  <div class="content-block-title">已过期</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
                <div id="todayTasks" style="display:none;">
                  <div class="content-block-title">今天</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
                <div id="tomorrowTasks" style="display:none;">
                  <div class="content-block-title">明天</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
                <div id="thisWeekTasks" style="display:none;">
                  <div class="content-block-title">本周</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
                <div id="nextWeekTasks" style="display:none;">
                  <div class="content-block-title">下周</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
                <div id="laterTasks" style="display:none;">
                  <div class="content-block-title">以后</div>
                  <div class="list-block">
                    <ul class="taks-list"></ul>
                  </div>
                </div>
              </div>
              <div class="content-block">
                <p class="buttons-row">
                  <a href="#" id="link-task-doing-more" class="button button-success button-big" style="display:none;">查看更多...</a>
                </p>
              </div>
            </div>
            <div id="tab2" class="tab">
              <div class="content-block">
                <div class="text-center" id="tasks-finish-none" style="display:none;">没有已经完成的任务</div>
                <div class="list-block" id="finishedTasks">
                  <ul class="taks-list"></ul>
                </div>
              </div>
              <div class="content-block">
                <p class="buttons-row">
                  <a href="#" id="link-task-finish-more" class="button button-success button-big" style="display:none;">查看更多...</a>
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-new-task">
        <div class="content">
          <p class="text-center">创建任务</p>
          <div class="list-block">
            <ul>
              <li>
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title label">任务内容</div>
                    <div class="item-input">
                      <textarea id="task-new-title"></textarea>
                    </div>
                  </div>
                </div>
              </li>
              <li>
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title label">到期时间</div>
                    <div class="item-input">
                      <input type="text" id="task-new-dueDate">
                    </div>
                  </div>
                </div>
              </li>
              <li>
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title label">分类</div>
                    <div class="item-input">
                      <select id="task-new-category">
                        <option value="0">无分类</option>
<%
  if (taskCategory != null) {
    for (Map<String, Object> category:taskCategory) { %>
                        <option value="<%=category.get("TaskCategoryId")%>"><%=Util.HTMLEncode((String)category.get("TaskCategoryName"))%></option>
<%
    }
}
%>
                      </select>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
          </div>
          <div class="content-block">
            <div class="row">
              <div class="col-50"><a href="#" class="close-popup button button-big button-fill button-danger">取消</a></div>
              <div class="col-50"><a href="#" id="link-create-task" class="button button-big button-fill button-success">确定</a></div>
            </div>
          </div>
        </div>
      </div>

      <div class="page" id="page-deal">
        <header class="bar bar-nav">
          <h1 class="title" id="deal-title"><span>销售机会</span> <i class="icon iconfont icon-arrowdown"></i></h1>
          <a class="button button-link button-nav pull-right" id="link-deal-refresh" href="#">
            <span class="icon iconfont icon-refresh"></span>
          </a>
        </header>
        <div class="bar bar-header-secondary">
          <div class="searchbar">
            <a class="searchbar-cancel">取消</a>
            <div class="search-input">
              <label class="icon iconfont icon-search" for="search"></label>
              <input type="search" id='deal-search' placeholder='输入销售机会名称...'/>
            </div>
          </div>
        </div>
        <nav class="bar bar-tab">
          <a class="tab-item" href="#page-activity">
            <span class="icon iconfont icon-activity"></span>
            <span class="tab-label">动态</span>
          </a>
          <a class="tab-item" href="#page-customer">
            <span class="icon iconfont icon-customer"></span>
            <span class="tab-label">客户</span>
          </a>
          <a class="tab-item active" href="#">
            <span class="icon iconfont icon-deal"></span>
            <span class="tab-label">销售机会</span>
          </a>
          <a class="tab-item" href="#page-task">
            <span class="icon iconfont icon-task"></span>
            <span class="tab-label">任务</span>
          </a>
          <% if (user.isAdmin || user.isGroupAdmin) {%>
          <a class="tab-item" href="#page-statistics">
            <span class="icon iconfont icon-statistics"></span>
            <span class="tab-label">统计</span>
          </a>
          <%}%>
        </nav>
        <div class="content">
          <div class="content-block">
            <div class="buttons-row" id="deals-status-container">
              <a href="#" v="0" class="active button">全部</a>
              <a href="#" v="<%=Const.DEAL_STATUS_PENDING%>" class="button">跟踪中</a>
              <a href="#" v="<%=Const.DEAL_STATUS_WON%>" class="button">成功</a>
              <a href="#" v="<%=Const.DEAL_STATUS_LOST%>" class="button">失败</a>
            </div>
          </div>
          <div class="tabs">
            <div id="deal-tab1" class="tab active">
              <div id="deal-list"></div>
              <div class="content-block">
                <p class="buttons-row">
                  <a href="#" id="link-deal-more" class="button button-success button-big" style="display:none;">查看更多...</a>
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-deal-responsibleUser" >
        <div class="content-block">
          <p>请选择查看的员工 <a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
          <div class="list-block">
            <ul id="deal-responsibleUser-list">
<% if (user.isAdmin) {%>
              <li v="*" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >所有员工的销售机会</div>
                  </div>
                </div>
              </li>
<%}%>
              <li v="<%=user.userId%>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" >我的销售机会</div>
                  </div>
                </div>
              </li>
<%
  groupName = "";
  for (User u : users) {
    if (u.userId.equals(user.userId)) {
      continue;
    }
    if (!companyInfo.isGroupAdmin(user, u.groupId)) {
      continue;
    }
    String gn = companyInfo.getGroupName(u);
    if (!groupName.equals(gn) && gn != null) {
       groupName = gn; %>
              <li class="list-group-title"><%=Util.HTMLEncode(groupName)%></li>
<%
    }
%>
              <li v="<%=u.userId%>" class="item-link">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title" ><%=Util.HTMLEncode(u.name)%>的销售机会</div>
                  </div>
                </div>
              </li>
<%
  }
%>
            </ul>
          </div>
        </div>
      </div>

      <% if (user.isAdmin || user.isGroupAdmin) {%>
      <div class="page" id="page-statistics">
        <header class="bar bar-nav"><h1 class="title">统计</h1></header>
        <nav class="bar bar-tab">
          <a class="tab-item" href="#page-activity">
            <span class="icon iconfont icon-activity"></span>
            <span class="tab-label">动态</span>
          </a>
          <a class="tab-item" href="#page-customer">
            <span class="icon iconfont icon-customer"></span>
            <span class="tab-label">客户</span>
          </a>
          <a class="tab-item" href="#page-deal">
            <span class="icon iconfont icon-deal"></span>
            <span class="tab-label">销售机会</span>
          </a>
          <a class="tab-item" href="#page-task">
            <span class="icon iconfont icon-task"></span>
            <span class="tab-label">任务</span>
          </a>
          <a class="tab-item active" href="#">
            <span class="icon iconfont icon-statistics"></span>
            <span class="tab-label">统计</span>
          </a>
        </nav>
        <div class="content">
          <div class="list-block">
            <ul>
              <li class="item-content item-link" id="item-statistics-totalNum">
                <div class="item-inner">
                  <div class="item-title">客户新增/联系数量统计</div>
                </div>
              </li>
              <li class="item-content item-link" id="item-statistics-category">
                <div class="item-inner">
                  <div class="item-title">客户分类统计</div>
                </div>
              </li>
              <li class="item-content item-link" id="item-statistics-tag">
                <div class="item-inner">
                  <div class="item-title">客户标签统计</div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>

      <div class="popup" id="popup-statistics-chart">
        <div class="content-block">
          <p><a href="#" class="close-popup"><i class="pull-right icon iconfont icon-close"></i></a></p>
        </div>
        <div id="statistics-chart" style="width:100%;height:80%;text-align:center;padding:0 50px;margin-top:80px;"></div>
      </div>
      <%}%>
    </div>
  </body>
</html>